package cn.yunhe.entity;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

@Entity(name = "学生")
@Table(name = "student1")
public class Student implements Serializable {
    private int id;
    private String name;
    private Set<Course> courseSet=new HashSet<>();

    public Student() {
    }

    public Student(String name) {
        this.name = name;
    }

    public Student(int id, String name, Set<Course> courseSet) {
        this.id = id;
        this.name = name;
        this.courseSet = courseSet;
    }

    @Id
    @GeneratedValue
    @Column(name = "id")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Column(name = "name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @ManyToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    @JoinTable(name = ("middle_student1_course1"),
        joinColumns = @JoinColumn(name = ("msid")),
            inverseJoinColumns = @JoinColumn(name = ("mcid"))
    )
    public Set<Course> getCourseSet() {
        return courseSet;
    }

    public void setCourseSet(Set<Course> courseSet) {
        this.courseSet = courseSet;
    }
}
